package com.kzd.gtboon.main.popup

import android.content.Context
import android.view.Gravity
import android.view.View
import android.view.animation.Animation
import android.view.animation.TranslateAnimation
import android.widget.*
import com.kzd.gtboon.R
import com.kzd.gtboon.custom.setOnClickAntiShakeListener
import com.kzd.gtboon.entity.GameGift
import com.module.lemlin.image.loadImage
import razerdp.basepopup.BasePopupWindow
import java.lang.StringBuilder

class GiftButtonPopup(context: Context) : BasePopupWindow(context) {

    init {
        popupGravity = Gravity.BOTTOM
        setOverlayNavigationBar(false)
    }


    override fun onCreateContentView(): View {
        return createPopupById(R.layout.popup_gift_bottom)
    }

    override fun onViewCreated(contentView: View) {
        super.onViewCreated(contentView)
        contentView.findViewById<ImageView>(R.id.ivGiftBottomClose).setOnClickAntiShakeListener {
            dismiss()
        }
    }

    override fun onCreateShowAnimation(width: Int, height: Int): Animation {
        return TranslateAnimation(
            Animation.RELATIVE_TO_PARENT, 0f,
            Animation.RELATIVE_TO_PARENT, 0f,
            Animation.RELATIVE_TO_PARENT, 1f,
            Animation.RELATIVE_TO_PARENT, 0f
        ).apply { duration = 300L }
    }

    override fun onCreateDismissAnimation(): Animation {
        return TranslateAnimation(
            Animation.RELATIVE_TO_PARENT, 0f,
            Animation.RELATIVE_TO_PARENT, 0f,
            Animation.RELATIVE_TO_PARENT, 0f,
            Animation.RELATIVE_TO_PARENT, 1f
        ).apply { duration = 300L }
    }

    fun fillData(gameGift: GameGift): GiftButtonPopup {
        contentView.findViewById<ImageView>(R.id.ivGiftBottomIcon)
            .loadImage(gameGift.icon)
        contentView.findViewById<TextView>(R.id.tvGiftBottomName)
            .text = gameGift.name
        contentView.findViewById<TextView>(R.id.tvGiftBottomTime)
            .text = StringBuilder().append("有效期：").append(gameGift.end_time)
        contentView.findViewById<TextView>(R.id.tvGiftBottomContent)
            .text = gameGift.content
        contentView.findViewById<TextView>(R.id.tvGiftBottomUse)
            .text = gameGift.meth
        return this
    }

}